﻿
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>汇瑾园传媒</title>
    <link href="Content/css/framework-font.css" rel="stylesheet" />
    <link href="Content/css/framework-login.css" rel="stylesheet" />
    <script src="Content/js/jquery/jquery-2.1.1.min.js"></script>
    <script src="Content/js/cookie/jquery.cookie.js"></script>
    <script src="Content/js/base.js"></script>
    <!--<script src="Content/js/md5/jquery.md5.js"></script>-->
</head>
<body>
    <div class="wrapper">
        <div class="container">
            <div class="logo">
                <i class="fa fa-modx"></i>
                <h1><span>巴渝工匠杯样题</span></h1>
            </div>
            <form class="form">
                <div class="row">
                    <input id="txt_account" type="text" placeholder="用户名/手机号/邮箱">
                    <i class="fa fa-user"></i>
                </div>
                <div class="row">
                    <input id="txt_password" type="password" placeholder="登录密码">
                    <i class="fa fa-key"></i>
                </div>
                <div class="row">
                    <button id="login_button" type="button"><span>登录</span></button>
                </div>
                <div class="row">
                </div>
            </form>
            <div class="login_tips"></div>
        </div>
        <ul class="bg-bubbles">
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
    <div class="copyright">
        <a href="#" style="text-decoration:none;color:#fff;">巴渝工匠杯样题</a>
        <br>
        适用浏览器：IE8以上、360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗.
    </div>
    <script type="text/javascript">
        (function ($) {
            $.login = {
                formMessage: function (msg) {
                    $('.login_tips').find('.tips_msg').remove();
                    $('.login_tips').append('<div class="tips_msg"><i class="fa fa-question-circle"></i>' + msg + '</div>');
                },
                loginClick: function () {
                    var $username = $("#txt_account");
                    var $password = $("#txt_password");
                    if ($username.val() == "") {
                        $username.focus();
                        $.login.formMessage('请输入用户名/手机号/邮箱。');
                        return false;
                    } else if ($password.val() == "") {
                        $password.focus();
                        $.login.formMessage('请输入登录密码。');
                        return false;
                    } else {

                        $("#login_button").attr('disabled', 'disabled').find('span').html("loading...");

                        var data = JSON.stringify({
                            "account": $.trim($username.val()),
                            "password": $.trim($password.val())
                        });

                        $.ajax({
                            url: baseUrl() + "userInfo/login",
                            data: data,      
                            type: "post",
                            contentType: "application/json;charset=utf-8",
                            dataType: "json",
                            success: function (data) {

                                console.log(data.data.userName);

                                if (data.success == true) {
                                    setCookie('user', $.trim($username.val()), 60 * 60 * 60, '/');
                                    setCookie('password', $.trim($password.val()), 60 * 60 * 60, '/');
                                    setCookie('realname', data.data.userName, 60 * 60 * 60, '/');

                                    $("#login_button").find('span').html("登录成功，正在跳转...");
                                    window.setTimeout(function () {
                                        window.location.href = "Index.html";
                                    }, 500);

                                } else {
                                    $("#login_button").removeAttr('disabled').find('span').html("登录");
                                    $.login.formMessage(data.msg);
                                }
                            }
                        });
                    }
                },
                init: function () {
                    $('.wrapper').height($(window).height());
                    $(".container").css("margin-top", ($(window).height() - $(".container").height()) / 2 - 50);
                    $(window).resize(function (e) {
                        $('.wrapper').height($(window).height());
                        $(".container").css("margin-top", ($(window).height() - $(".container").height()) / 2 - 50);
                    });
                    var login_error = top.$.cookie('nfine_login_error');
                    if (login_error != null) {
                        switch (login_error) {
                            case "overdue":
                                $.login.formMessage("系统登录已超时,请重新登录");
                                break;
                            case "OnLine":
                                $.login.formMessage("您的帐号已在其它地方登录,请重新登录");
                                break;
                            case "-1":
                                $.login.formMessage("系统未知错误,请重新登录");
                                break;
                        }
                        top.$.cookie('nfine_login_error', '', { path: "/", expires: -1 });
                    }
                    $("#login_button").click(function () {
                        $.login.loginClick();
                    });
                    document.onkeydown = function (e) {
                        if (!e) e = window.event;
                        if ((e.keyCode || e.which) == 13) {
                            document.getElementById("login_button").focus();
                            document.getElementById("login_button").click();
                        }
                    }
                }
            };
            $(function () {
                $.login.init();
            });
        })(jQuery);

        //hours为空字符串时,cookie的生存期至浏览器会话结束。
        //hours为数字0时,建立的是一个失效的cookie,
        //这个cookie会覆盖已经建立过的同名、同path的cookie（如果这个cookie存在）。
        function setCookie(name, value, hours, path) {
            var name = escape(name);
            var value = escape(value);
            var expires = new Date();
            expires.setTime(expires.getTime() + hours * 3600000);
            path = path == "" ? "" : ";path=" + path;
            _expires = (typeof hours) == "string" ? "" : ";expires=" + expires.toUTCString();
            document.cookie = name + "=" + value + _expires + path;
        }
    </script>

    <!-- Visual Studio Browser Link -->
    <!--<script type="application/json" id="__browserLink_initializationData">
        {"appName":"Chrome","requestId":"7971704200354959957661532cdcc1b8"}
    </script>
    <script type="text/javascript" src="http://localhost:7908/ef728827ef4f45139760916d83086031/browserLink" async="async"></script>-->
    <!-- End Browser Link -->

</body>
</html>
